<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Reset Password</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="./defaultf.css" rel="stylesheet" type="text/css" media="all" />
    <link rel="stylesheet" type="text/css" href="./jquery/easyui.css">
    <link rel="stylesheet" type="text/css" href="./jquery/icon.css">
    <!-- CSS for Reset pwd -->
    <link href="./css/bootstrap.css" rel="stylesheet">
    <link href="./css/bootstrap.min.css" rel="stylesheet">
	<style>
    	.alert-danger {
    		background-image: -webkit-gradient(linear,left 0,left 100%,from(#f2dede),to(#e7c3c3));
    		background-image: -webkit-linear-gradient(top,#f2dede 0,#e7c3c3 100%);
    		background-image: -moz-linear-gradient(top,#f2dede 0,#e7c3c3 100%);
    		background-image: linear-gradient(to bottom,#f2dede 0,#e7c3c3 100%);
    		background-repeat: repeat-x;
    		border-color: #dca7a7;
    		filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede',endColorstr='#ffe7c3c3',GradientType=0);
		}
		.alert-danger {
    		color: rgb(185, 74, 72);
    		background-color: rgb(242, 222, 222);
    		border-color: rgb(235, 204, 209);
		}
    </style>
</head>
<?php
    define('CONFIG_FILE',true);
    include './config.php';
    
    define('DB_FILE',true);
    require_once './Tool/DB/SqlDBManager.class.php';

    if(!empty($_GET['hashValue'])){
        $hashValue=$_GET['hashValue'];
    }else{
        $url="./Index.php";
        include_once './Tool/Common/Redirect.php';
        exit();
    }
 
    $sqlDBManager= new SqlDBManager();

    $sql="SELECT HashValue from token where HashValue=?";
    $parameters=array($hashValue);

    $res=$sqlDBManager->queryRow($sql,$parameters);

    if(empty($res)){
        die("Invalid link");
    }
?>
<body>
    <div id="wrap">
    	<div id="header-wrapper">
    		<div id="header" class="container">
    			<div id="logo">
    				<img src="./images/eldercare.gif" alt="" title="" border="0" width="270" height="70"/>
    			</div>
    			</p>
    			<br/>
    			<br/>
    		</div>
    	</div>
    </div>
    <div id="menu-wrapper">
        <div id="menu">
            <ul>
				<li class="current_page_item" ><a href="#" accesskey="1" title="">Reset Password</a></li>            
            </ul>
        </div>
    </div>
    <div>
        <div id="wrap-content" style="margin: 0px auto; padding: 10px">
            <fieldset>
                <p></p>
                <p></p>
                <h4>Reset Password</h4>
                <ul class="nav nav-tabs" id="myTab">
                    <li class="active"><a href="#token-tab" data-toggle="tab">Token Key</a></li>
                </ul>

                <div class="tab-content">
                    <div class="tab-pane fade in active" id="token-tab">
                        <form action="./LoginController/ResetPwdProcess.php" method="post" id="tokenKeyForm">
                            <table align="center">
                                <tr>
                                    <td>Please Enter Token:</td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="text" name="tokenKey" style="width:220px" maxlength="40" data-validation="required"/>
                                         <input type="hidden" name="hashValue" value="<?php echo $hashValue?>"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"></td>
                                </tr>
                                <tr>
                                    <td align="middle">
                                        <input type="submit" value="Submit" button class="btn" style="width:70px"/>&nbsp;      
                                        <input type="reset" onclick="resend()" value="Resend" button class="btn" style="width:70px"/>&nbsp;  
                                        <input type="reset" onclick="redirect()" value="Back" button class="btn" style="width:70px"/>  
                                    </td>
                                </tr>
                            </table>
                            
                        </form>
                    </div>
                <p style="vertical-align: middle; text-align: center">
                </p>    
            </fieldset>
			<?php
				if(!empty($_GET['msgno'])){
					$msgno=$_GET['msgno'];
					//No token
					if($msgno==1){
                        $error="Please enter a token value.";
					}else if($msgno==2){
                        $error="Invalid Token Format.";
                    }else if($msgno==3){
                        $error="Token does not exist.";
					}else if($msgno==4){
                        $error="Token expired.";
					}else if($msgno==5){
                        $error="A new password has sent to your email address.";
                    }else if($msgno==6){
                        $error="SMTP server time out. Please check your network.";
					}else if($msgno==7){
                        $error="Email new password failed due to database error. Please contact with IT Support Team.";
                    }
				}
			?>
            <div style="text-align:center; color:red" id="resendToken" name="resendToken"><?php if(isset($error)){echo $error;} ?></div>
            <!--</form>-->
        </div>
    </div>
</body>
<!-- js for Reset pwd -->
<script src="https://code.jquery.com/jquery.js"></script>
<script type="text/javascript" src="./js/bootstrap.min.js"></script>

<script src="./jquery/jquery.min.js"></script>
<script type="text/javascript" src="./jquery/jquery-1.6.min.js"></script>
<script type="text/javascript" src="./jquery/jquery-1.4.4.min.js"></script>
<!-- validation -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="./js/jquery.form-validator.min.js" type="text/javascript"></script>
<script>
	$.validate({
	    form: '#tokenKeyForm',
	    validateOnBlur: false, // disable validation when input looses focus
	    errorMessagePosition: 'top', // Instead of 'element' which is default
	    scrollToTopOnError: false, // Set this property to true if you have a long form
	});

    <!-- cancel button -->
    function redirect(){
		var url = "./Index.php";
		location.href=url;
    }

    //resend 
    function resend(){
        $('[name="resendToken"]').text('');
        var flagResend=0;
        $.ajax({
            async : false,
            type : "POST",
            url : "./LoginController/ForgotPwdProcess.php?Resend=true", //the page/method you wanna validate
            data : {
                hashValue: $('[name="hashValue"]').val()
            },
            success : function(data) {
                flagResend=data;
            }
        });
        if(flagResend==1){
            $('[name="resendToken"]').text('Resend Token Key failed due to cannot retrieve user email address. Please go back forgot pasword page.');
        }else if(flagResend==2){
            $('[name="resendToken"]').text('A new Token Key has sent to your email.');
        }else if(flagResend==0){
            $('[name="resendToken"]').text('Resend Token Key failed due to network is down or SMTP server time out.');
        }
    }

	$(function () {
		$('#myTab a:first').tab('show')
	})
</script>
</html>


